/**
 * create by young (young2f@outlook.com) on 2020/9/19
 */
'use strict';
import React, {Component} from 'react';
import {AutoComplete, Button, Col, Input, Row} from 'antd';

class AutoCompleteAndCreate extends Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {

  }


  onCreateClick = () => {
    const {createUrl, onCreateClick} = this.props;
    if (onCreateClick) {
      onCreateClick();
      return;
    }
    if (createUrl) {
      const w = window.open('about:blank');
      w.location.href = createUrl;
    }
  };

  render() {
    let {dataSource, allowClear, onSelect, defaultValue, disabled, style} = this.props;

    return (
      <div>
        <Row gutter={1}>
          <Col span={12}>
            <AutoComplete
              disabled={disabled}
              dataSource={dataSource}
              allowClear={allowClear}
              style={style}
              defaultValue={defaultValue}
              onClick={onSelect ? onSelect.bind(this) : undefined}
              onSearch={this.onCreateClick.bind(this)}></AutoComplete>
          </Col>
          <col span={12}>
            <Button>新建</Button>
          </col>
        </Row>
      </div>
    );
  }
}

export default AutoCompleteAndCreate;
